package com.cndym.adapterForMobile.mobile.function;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cndym.adapterForMobile.BaseFunction;
import com.cndym.exception.ErrCode;
import com.cndym.utils.Utils;
import com.zch.matches.producer.ISportMatchesProducer;

/**
 * 对比赛进行关注或取消关注
 * 
 * @author 朱林虎
 *
 */
@Component
public class FutureSportMatchesFunc extends BaseFunction {

	private Logger logger = Logger.getLogger(getClass());

	@Autowired
	private ISportMatchesProducer sportMatchesProducer;

	@Override
	public Map<String, String> function(Map<String, String> map) {
		Map<String, String> paramMap = paraMap(map);

		if (Utils.isEmpty(paramMap.get("homeId"))) {
			logger.error("homeId(主队id)不存在，该请求无效！");
			return noBodyReMap(ErrCode.E4504);
		}
		if (Utils.isEmpty(paramMap.get("awayId"))) {
			logger.error("awayId(客队id)不存在，该请求无效！");
			return noBodyReMap(ErrCode.E4505);
		}
		
		if (Utils.isEmpty(paramMap.get("lotteryCode"))) {
			logger.error("彩种不存在，该请求无效！");
			return noBodyReMap(ErrCode.E3300);
		}
		
		Map<String, Object> resMap = null;
		if ("200".equals(paramMap.get("lotteryCode"))) {
			resMap=sportMatchesProducer.futureSportMatches(paramMap);
			if (null == resMap) {
				return failure();
			}
			return successObj(resMap);
		}
		if ("201".equals(paramMap.get("lotteryCode"))) {
			return successObj(new HashMap<String, Object>());
		}
		return noBodyReMap(ErrCode.E8101);
	}
}
